home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Drawing / GrafPortObject.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  1.7 KB  |  94 lines  |  [TEXT/CWIE]

  1. // GrafPortObject.cp
  2.  
  3. #ifndef GrafPortObject_h
  4. #include "GrafPortObject.h"
  5. #endif
  6. #ifndef QuickDrawError_h
  7. #include "QuickDrawError.h"
  8. #endif
  9.  
  10. GrafPortObject::GrafPortObject()
  11.   {
  12.     OpenCPort( &UncheckedColorCast() );
  13.     QuickDrawError::Check().Throw();
  14.   }
  15.  
  16. GrafPortObject::~GrafPortObject()
  17.   {
  18.     CloseCPort( &ColorCast() );
  19.     QuickDrawError::Check().Throw();
  20.   }
  21.  
  22. Rectangle GrafPortObject::LocalBitMapBounds() const
  23.   {
  24.     return InColor()
  25.                 ? (*UncheckedColorCast().portPixMap)->bounds
  26.                 : portBits.bounds;
  27.   }
  28.  
  29. PointObject GrafPortObject::GlobalToLocal() const
  30.   {
  31.     return LocalBitMapBounds().TopLeft();
  32.   }
  33.  
  34. PointObject GrafPortObject::LocalToGlobal() const
  35.   {
  36.     return -GlobalToLocal();
  37.   }
  38.  
  39. Rectangle GrafPortObject::GlobalBounds() const
  40.   {
  41.     Rectangle bounds( LocalBounds() );
  42.     bounds += LocalToGlobal();
  43.     return bounds;
  44.   }
  45.  
  46. RGBColor GrafPortObject::ForegroundColor() const
  47.   {
  48.     Assert( IsCurrent() );
  49.     Assert( InColor() );
  50.     RGBColor result;
  51.     GetForeColor( &result );
  52.     return result;
  53.   }
  54.  
  55. RGBColor GrafPortObject::BackgroundColor() const
  56.   {
  57.     Assert( IsCurrent() );
  58.     Assert( InColor() );
  59.     RGBColor result;
  60.     GetBackColor( &result );
  61.     return result;
  62.   }
  63.  
  64. ::Face GrafPortObject::Face() const
  65.   {
  66.     return ::Face( Font(), TextSize(), Style() );
  67.   }
  68.  
  69. void GrafPortObject::SetFace( const ::Face& face )
  70.   {
  71.     Assert( IsCurrent() );
  72.  
  73.     if ( Font() != face.Font() )
  74.         SetFont( face.Font() );
  75.     
  76.     if ( TextSize() != face.Size() )
  77.         SetTextSize( face.Size() );
  78.     
  79.     if ( Style() != face.Style() )
  80.         SetStyle( face.Style() );
  81.   }
  82.  
  83. void GrafPortObject::SetCharacterStretch( Fixed stretch )
  84.   {
  85.     Assert( IsCurrent() );
  86.     Assert( InColor() );
  87.     CharExtra( stretch );
  88.   }
  89.  
  90. Fixed GrafPortObject::CharacterStretch() const
  91.   {
  92.     return ColorCast().chExtra;
  93.   }
  94.